const BaseIpcHandler = require('../BaseIpcHandler');
const path = require('path');

class PathJoinHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> PathJoinHandler params = ', params);
        const dirs = JSON.parse(params.dirs);

        // 业务逻辑
        let result = null;
        try {
            const pathJoin = path.join(...dirs);
            result = { code: 0, msg: pathJoin };
        } catch (error) {
            result = { code: -1, msg: error.message };
        }

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = PathJoinHandler;
